package scau.erps.view.dashboard;

import java.awt.Font;
import java.util.List;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

import scau.erps.app.Erps;
import scau.erps.entity.Incomestatement;
import scau.erps.service.IncomestatementService;
import scau.erps.service.impl.IncomestatementServiceImpl;

/**
 * 净利润柱状图 * 
 * @author outsider
 * 
 */
public class ProfitChart {
	/**
	 * 得到图片
	 * 
	 */
	public static JFreeChart getChart() {
		JFreeChart chart = createChart(createDataset());
		return chart;
	}

	/**
	 * 数据
	 */
	private static CategoryDataset createDataset() {
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		IncomestatementService incomestatementService=Erps.getIocInstance().get(IncomestatementServiceImpl.class);
		List<Incomestatement> list=incomestatementService.getIncomestatementByTeam(Erps.getCurrentTeam().getId());
		

		
		for (Incomestatement incomestatement : list){
            if (incomestatement.getYear().equals("Y8")) continue;
			dataset.setValue(incomestatement.getNetProfit(), "", incomestatement.getYear());
		}
		return dataset;
	}

	/**
	 * 绘制折线
	 */
	private static JFreeChart createChart(CategoryDataset dataset) {
		JFreeChart jfreeChart = ChartFactory.createBarChart3D("公司年净利润","年份", "年净利润(M)", dataset, PlotOrientation.VERTICAL, true, false,false);
		jfreeChart.setTitle(new TextTitle("公司年净利润", new Font("宋体", Font.BOLD + Font.ITALIC, 20)));
		CategoryPlot plot = (CategoryPlot) jfreeChart.getPlot();
		CategoryAxis categoryAxis = plot.getDomainAxis();
		categoryAxis.setLabelFont(new Font("仿宋", Font.ROMAN_BASELINE, 12));
		return jfreeChart;
	}
}
